class MassEmail < ActionMailer::Base

  def newsletter(contact, newsletter)
    subject    newsletter.subject
    recipients contact.email
    from       '"Greene Hill Food Coop" <info@greenehillfoodcoop.com>'
    sent_on    Time.now
    body       :contact => contact, :newsletter => newsletter
    headers(   'return-path' => 'bounces@greenehillfoodcoop.com',
               'Precedence' => 'bulk',
               'List-Unsubscribe' => "<#{unsubscribe_url(:token => contact.auth_token, :only_path => false)}>")
    
  end
  
  # Add our own implementation of deliver_newsletter, which 
  # calls the superclass's method, but logs successfuly delivery
  def MassEmail.deliver_newsletter(contact, newsletter, log = true)
    mail = super(contact, newsletter)
    
    SentEmail.create(:contact => contact, :newsletter => newsletter) if log

    # return the new mail object
    mail
  end
  
end
